package com.zto.sch.advance.algorithms.book.grokking;

import com.zto.sch.base.util.CommonUtil;

import java.util.Arrays;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-07-20 20:39
 **/
public class 数组递归相加 {
    public static void main(String[] args) {
        Integer[] array = CommonUtil.getRandomArray(4);
        System.out.println(Arrays.toString(array));

        int sumCount = sumArr(array, 0);
        System.out.println("数组的和是:" + sumCount);
    }

    private static int sumArr(Integer[] array, int begin) {
        if (begin == array.length) {
            return 0;
        }
        int x = sumArr(array, begin + 1);

        return x + array[begin];
    }

}
